function PageApplication(container, lang) {
  this._container = container;
  this._lang = lang;

  this._createElement();
};

PageApplication.prototype._createElement = function() {
  var _self = this;
  this._bContainer = null;
  this._bDate = SimpleDate.create(1982, 10, 24);
  this._bLabel = document.createElement('a');
  this._bLabel.href = '#';
  this._bLabel.appendChild(document.createTextNode(SimpleDate.format(this._bDate, false)));
  this._bLabel.onclick = function() { _self._changeDate.call(_self);
                                      return false;
                                    };

  this._qualification = document.createElement('select');
  this._qualification.options[this._qualification.options.length] = new Option('-');
  this._qualification.options[this._qualification.options.length] = new Option('初中');
  this._qualification.options[this._qualification.options.length] = new Option('高中');
  this._qualification.options[this._qualification.options.length] = new Option('大专');
  this._qualification.options[this._qualification.options.length] = new Option('本科');

  this._apply = document.createElement('select');
  this._apply.options[this._apply.options.length] = new Option('-');
  this._apply.options[this._apply.options.length] = new Option('语言预备课程');
  this._apply.options[this._apply.options.length] = new Option('大学预科课程');
  this._apply.options[this._apply.options.length] = new Option('国家管理学大专');
  this._apply.options[this._apply.options.length] = new Option('国家商科大专');
  this._apply.options[this._apply.options.length] = new Option('纽西兰商科大专');
  this._apply.options[this._apply.options.length] = new Option('游学');

  this._time = document.createElement('select');
  this._time.options[this._time.options.length] = new Option('-');
  this._time.options[this._time.options.length] = new Option('2009年春季');
  this._time.options[this._time.options.length] = new Option('2009年秋季');
  this._time.options[this._time.options.length] = new Option('2010年春季');
  this._time.options[this._time.options.length] = new Option('2010年秋季');
  this._time.options[this._time.options.length] = new Option('2011年春季');
  this._time.options[this._time.options.length] = new Option('2011年秋季');

  var tr, td, div;
  var table = document.createElement('table');
  table.className = 'app';
  table.style.width = '100%';
  tr = table.insertRow(-1);
  td = tr.insertCell(-1);
  td.className = 'header';
  td.appendChild(document.createTextNode('申请人姓名 (必填)'));
  td = tr.insertCell(-1);
  this._name = DOMUtils.createInput(null, null, 'text', '', null);
  td.appendChild(this._name);
  tr = table.insertRow(-1);
  td = tr.insertCell(-1);
  td.className = 'header';
  td.appendChild(document.createTextNode('性别 (必填)'));
  td = tr.insertCell(-1);
  td.appendChild(this._createGeneder());
  tr = table.insertRow(-1);
  td = tr.insertCell(-1);
  td.className = 'header';
  td.appendChild(document.createTextNode('出生日期 (必填)'));
  td = tr.insertCell(-1);
  td.appendChild(this._bLabel);
  tr = table.insertRow(-1);
  td = tr.insertCell(-1);
  td.className = 'header';
  td.appendChild(document.createTextNode('民族 (必填)'));
  td = tr.insertCell(-1);
  this._ethnicity = DOMUtils.createInput(null, null, 'text', '', null);
  td.appendChild(this._ethnicity);
  tr = table.insertRow(-1);
  td = tr.insertCell(-1);
  td.className = 'header';
  td.appendChild(document.createTextNode('家庭地址 (必填)'));
  td = tr.insertCell(-1);
  this._address1 = DOMUtils.createInput(null, null, 'text', '', null);
  td.appendChild(this._address1);
  tr = table.insertRow(-1);
  td = tr.insertCell(-1);
  td.className = 'header';
  td = tr.insertCell(-1);
  this._address2 = DOMUtils.createInput(null, null, 'text', '', null);
  td.appendChild(this._address2);
  tr = table.insertRow(-1);
  td = tr.insertCell(-1);
  td.className = 'header';
  td = tr.insertCell(-1);
  this._address3 = DOMUtils.createInput(null, null, 'text', '', null);
  td.appendChild(this._address3);
  tr = table.insertRow(-1);
  td = tr.insertCell(-1);
  td.className = 'header';
  td.appendChild(document.createTextNode('户籍城市 (必填)'));
  td = tr.insertCell(-1);
  this._city = DOMUtils.createInput(null, null, 'text', '', null);
  td.appendChild(this._city);
  tr = table.insertRow(-1);
  td = tr.insertCell(-1);
  td.className = 'header';
  td.appendChild(document.createTextNode('邮政编码 (可选)'));
  td = tr.insertCell(-1);
  this._postCode = DOMUtils.createInput(null, null, 'text', '', null);
  td.appendChild(this._postCode);
  tr = table.insertRow(-1);
  td = tr.insertCell(-1);
  td.className = 'header';
  td.appendChild(document.createTextNode('身份证号码 (可选)'));
  td = tr.insertCell(-1);
  this._id = DOMUtils.createInput(null, null, 'text', '', null);
  td.appendChild(this._id);
  tr = table.insertRow(-1);
  td = tr.insertCell(-1);
  td.className = 'header';
  td.appendChild(document.createTextNode('护照号码 (可选)'));
  td = tr.insertCell(-1);
  this._passport = DOMUtils.createInput(null, null, 'text', '', null);
  td.appendChild(this._passport);
  tr = table.insertRow(-1);
  td = tr.insertCell(-1);
  td.className = 'header';
  td.appendChild(document.createTextNode('宗教信仰 (可选)'));
  td = tr.insertCell(-1);
  this._religious = DOMUtils.createInput(null, null, 'text', '', null);
  td.appendChild(this._religious);
  tr = table.insertRow(-1);
  td = tr.insertCell(-1);
  td.className = 'header';
  td.appendChild(document.createTextNode('学历 (必填)'));
  td = tr.insertCell(-1);
  td.appendChild(this._qualification);
  tr = table.insertRow(-1);
  td = tr.insertCell(-1);
  td.className = 'header';
  td.appendChild(document.createTextNode('毕业院校 (必填)'));
  td = tr.insertCell(-1);
  this._school = DOMUtils.createInput(null, null, 'text', '', null)
  td.appendChild(this._school);
  tr = table.insertRow(-1);
  td = tr.insertCell(-1);
  td.className = 'header';
  td.appendChild(document.createTextNode('电话 (必填)'));
  td = tr.insertCell(-1);
  this._phone = DOMUtils.createInput(null, null, 'text', '', null)
  td.appendChild(this._phone);
  tr = table.insertRow(-1);
  td = tr.insertCell(-1);
  td.className = 'header';
  td.appendChild(document.createTextNode('手机 (必填)'));
  td = tr.insertCell(-1);
  this._mobile = DOMUtils.createInput(null, null, 'text', '', null);
  td.appendChild(this._mobile);
  tr = table.insertRow(-1);
  td = tr.insertCell(-1);
  td.className = 'header';
  td.appendChild(document.createTextNode('电子邮件 (必填)'));
  td = tr.insertCell(-1);
  this._email = DOMUtils.createInput(null, null, 'text', '', null);
  td.appendChild(this._email);
  tr = table.insertRow(-1);
  td = tr.insertCell(-1);
  td.className = 'header';
  td.appendChild(document.createTextNode('传真 (可选)'));
  td = tr.insertCell(-1);
  this._fax = DOMUtils.createInput(null, null, 'text', '', null);
  td.appendChild(this._fax);
  tr = table.insertRow(-1);
  td = tr.insertCell(-1);
  td.className = 'header';
  td.appendChild(document.createTextNode('雅思成绩 (可选)'));
  td = tr.insertCell(-1);
  this._ielts = DOMUtils.createInput(null, null, 'text', '', null);
  td.appendChild(this._ielts);
  tr = table.insertRow(-1);
  td = tr.insertCell(-1);
  td.className = 'header';
  td.appendChild(document.createTextNode('托福成绩 (可选)'));
  td = tr.insertCell(-1);
  this._toefl = DOMUtils.createInput(null, null, 'text', '', null);
  td.appendChild(this._toefl);
  tr = table.insertRow(-1);
  td = tr.insertCell(-1);
  td.className = 'header';
  td.appendChild(document.createTextNode('申请课程 (必填)'));
  td = tr.insertCell(-1);
  td.appendChild(this._apply);
  tr = table.insertRow(-1);
  td = tr.insertCell(-1);
  td.className = 'header';
  td.appendChild(document.createTextNode('申请入读时间 (必填)'));
  td = tr.insertCell(-1);
  td.appendChild(this._time);
  tr = table.insertRow(-1);
  td = tr.insertCell(-1);
  td.colSpan = 2;
  td.align = 'center';
  this._submit = DOMUtils.createInput(null, null, 'submit', '递交', null);
  this._submit.onclick = function() { _self._submitApplication.call(_self); }
  td.appendChild(this._submit);
  this._container.appendChild(table);
};

PageApplication.prototype._changeDate = function() {
  var _self = this;
  this._bContainer = document.createElement('div');
  this._bContainer.className = 'popupBase';
  this._bContainer.style.left = DOMUtils.findPos(this._bLabel)[0] + 'px';
  this._bContainer.style.top = DOMUtils.findPos(this._bLabel)[1] + 'px';
  var ds = new DateSelect(this._bDate, null, { container: this._bContainer });
  ds._selectFunc = function(sd) { _self._selectDate.call(_self, sd); };
  document.body.appendChild(this._bContainer);
};

PageApplication.prototype._selectDate = function(sd) {
  if (sd) {
    this._bDate = sd;
    this._showDate(sd);
  }
  document.body.removeChild(this._bContainer);
};

PageApplication.prototype._showDate = function(sd) {
  this._bLabel.firstChild.nodeValue = SimpleDate.format(sd, false);
};

PageApplication.prototype._createGeneder = function() {
  var div;
  div = document.createElement('div');
  this._male = DOMUtils.createInput('gender', null, 'radio', null, null);
  this._male.defaultChecked = true;
  div.appendChild(document.createTextNode('男'));
  div.appendChild(this._male);
  this._female = DOMUtils.createInput('gender', null, 'radio', null, null);
  div.appendChild(document.createTextNode('女'));
  div.appendChild(this._female);
  return div;
};

PageApplication.prototype._submitApplication = function() {
  if (this._name.value == '') {
    window.alert('请您填写申请人姓名');
    return;
  }
  if (this._ethnicity.value == '') {
    window.alert('请您填写申请人民族');
    return;
  }
  if (this._address1.value == '' && this._address2.value == '' && this._address3.value == '') {
    window.alert('请您填写申请人地址');
    return;
  }
  if (this._city.value == '') {
    window.alert('请您填写申请人户籍城市');
    return;
  }
  if (this._qualification.selectedIndex == 0) {
    window.alert('请您选择申请人学历');
    return;
  }
  if (this._school.value == '') {
    window.alert('请您填写申请人毕业院校');
    return;
  }
  if (this._phone.value == '') {
    window.alert('请您填写申请人电话');
    return;
  }
  if (this._mobile.value == '') {
    window.alert('请您填写申请人手机');
    return;
  }
  if (this._email.value == '') {
    window.alert('请您填写申请人电子邮件');
    return;
  }
  if (this._apply.selectedIndex == 0) {
    window.alert('请您选择申请课程');
    return;
  }
  if (this._time.selectedIndex == 0) {
    window.alert('请您选择申请入学时间');
    return;
  }
  var body = { name: this._name.value,
               gender: (this._male.checked) ? '男' : '女',
               birth: SimpleDate.format(this._bDate, false),
               ethnicity: this._ethnicity.value,
               address1: this._address1.value,
               address2: this._address2.value,
               address3: this._address3.value,
               city: this._city.value,
               qualification: this._qualification.options[this._qualification.selectedIndex].text,
               school: this._school.value,
               phone: this._phone.value,
               mobile: this._mobile.value,
               email: this._email.value,
               apply: this._apply.options[this._apply.selectedIndex].text,
               time: this._time.options[this._time.selectedIndex].text };

  var xmlHttp = new Ajax(this._completeSubmitApplication, { context: this });
  xmlHttp._request('phpmailer/mailrequest.php', 'mail=' + JSON.stringify(body));
};

PageApplication.prototype._completeSubmitApplication = function(xml, hesError) {
  DOMUtils.removeChildElements(this._container);

  var data = ParseUtils.parseXML(xml);console.log(data);
  if (data == '1') {
    this._container.appendChild(document.createTextNode('您的申请已经被接受，我们会通过您留下的联系方式与您联系'));
  } else {
    this._container.appendChild(document.createTextNode('非常抱歉，由于网络关系，请重新填写申请．'));
  }
};